from django.db import models

# Create your models here.


class Terminal(models.Model):
    class Meta:
        verbose_name_plural = "终端信息"
    IP = models.CharField(max_length=20)
    SN = models.CharField(max_length=20)
    MAC = models.CharField(max_length=20)
    address = models.CharField("位置", max_length=100)
    administrator = models.CharField("管理员", max_length=20)
    #current_status = models.CharField(max_length=20)

    def __str__(self):
        return self.IP


class Department(models.Model):
    class Meta:
        verbose_name_plural = "部门信息"
    department = models.CharField("部门", max_length=100)
    leader = models.CharField("负责人", max_length=20)

    def __str__(self):
        return self.department


class Members(models.Model):
    class Meta:
        verbose_name_plural = "员工信息"
    Member_wx_id = models.CharField("微信ID", max_length=100, primary_key=True)
    Member = models.CharField("员工姓名", max_length=20)
    department_id = models.ForeignKey(Department, on_delete=models.CASCADE)

    def __str__(self):
        return self.Member


class Registration(models.Model):
    class Meta:
        verbose_name_plural = "生产终端使用登记"
    department = models.ForeignKey(Department, on_delete=models.CASCADE)
    user = models.CharField("使用人", max_length=20)
    terminal = models.ForeignKey(Terminal, on_delete=models.CASCADE)
    reason = models.CharField("使用原因描述", max_length=1000)
    start_time = models.DateTimeField("开始使用时间", )
    end_time = models.DateTimeField("结束使用时间", )
    applicant = models.CharField("申请人", max_length=20, null=True)
    application_time = models.DateTimeField("申请时间", auto_now=True)
    Approver = models.CharField("审批人", max_length=20,null=True)

